export default {
    menus() {
        return [
            {
                cn: '首页',
                en: 'Home',
                pages: [
                    { cn: '欢迎使用后台系统', en: 'Welcome', path: 'home' },
                ]
            }, {
                cn: '系统管理',
                en: 'System',
                pages: [
                    { cn: '个人中心', en: 'My', path: 'my' },
                    { cn: '权限管理', en: 'Role', path: 'roleList' },
                    { hidden: true, cn: '权限详情', en: 'Role Detail', path: 'roleDetail' },
                    { cn: '后台用户', en: 'Staff', path: 'userList' },
                    { hidden: true, cn: '后台用户详情', en: 'Staff Detail', path: 'userDetail' },
                ]
            }
        ]
    },
    filter(hidden, paths) {
        const menus = this.menus()
        for (let menuIndex = menus.length - 1; menuIndex >= 0; menuIndex--) {
            const menu = menus[menuIndex]
            if (menu != null && menu.pages != null) {
                for (let pageIndex = menu.pages.length - 1; pageIndex >= 0; pageIndex--) {
                    let splice = false
                    const page = menu.pages[pageIndex]
                    if (hidden === true && !page.hidden) {
                        splice = true
                    }
                    if (hidden === false && page.hidden) {
                        splice = true
                    }
                    if (paths != null && paths.length > 0 && !paths.includes(page.path)) {
                        splice = true
                    }
                    if (splice) {
                        menu.pages.splice(pageIndex, 1)
                    }
                }
            }
            if (menu == null || menu.pages == null || menu.pages.length == 0) {
                menus.splice(menuIndex, 1)
            }
        }
        return menus
    }
}